<include file="Public:header" />
<style>
table tbody tr{cursor:move;}
</style>
<script type="text/javascript" src="__PUBLIC__/js/jscolor/jscolor.js"></script>
<div class="container">
	<div class="page-header">
		<h4>{:L('SYSTEM_SETTING')}</h4>
	</div>
	<include file="Public:alert" />
	<div class="tabbable">
		<ul class="nav nav-tabs">
			<li><a href="{:U('setting/defaultInfo')}">{:L('BASIC_SYSTEM_SETTING')}</a></li>
			<li><a href="{:U('setting/smtp')}">{:L('SMTP_SETTING')}</a></li>
			<li class="active"><a href="{:U('setting/fields')}">{:L('CUSTOMIZING_FIELDS_SETTING')}</a></li>		
			<li><a href="{:U('navigation/setting')}">{:L('SYSTEM_NAVIGATION_SETTING')}</a></li>
			<li><a href="{:U('setting/weixin')}">{:L('WHCHAT_SETTING')}</a></li>
		</ul>
	</div>
	<div class="row">
		<div class="span2 knowledgecate">
			<ul class="nav nav-list">
				<li class="active">
					<a href="javascript:void(0);" onclick="color_box()">{:L('CUSTOMIZING_FIELDS_SETTING')}</a>
				</li>
				<li><a <if condition="$_GET['model'] eq 'customer' || $_GET['model'] eq ''">class="active"</if> href="{:U('setting/fields', 'model=customer')}"><i class="icon-chevron-right"></i>{:L('CUSTOMER_FIELDS_SETTING')}</a></li>
				<li><a <if condition="$_GET['model'] eq 'business'">class="active"</if>  href="{:U('setting/fields', 'model=business')}"><i class="icon-chevron-right"></i>{:L('BUSINESS_FIELDS_SETTING')}</a></li>
				<li><a <if condition="$_GET['model'] eq 'product'">class="active"</if>  href="{:U('setting/fields', 'model=product')}"><i class="icon-chevron-right"></i>{:L('PRODUCT_FIELDS_SETTING')}</a></li>
				<li><a <if condition="$_GET['model'] eq 'leads'">class="active"</if>  href="{:U('setting/fields', 'model=leads')}"><i class="icon-chevron-right"></i>{:L('CLUES_TO_THE_FIELDS')}</a></li>
				<li><a href="{:U('knowledge/category')}"><i class="icon-chevron-right"></i>{:L('KNOWLEDGE_CATEGORY')}</a></li>
			</ul>
		</div>
        <form action="{:U('setting/fielddelete')}" method="post" onSubmit="return checkForm()">
            <div class="span10">
                <p><div class="bulk-actions align-left"> 
                    <button type="submit" class="btn"><i class="icon-remove"></i>&nbsp;{:L('DELETE')}</button>&nbsp;
					<button class="btn" type="button" id="sort_btn"><span class="icon-file"></span>&nbsp;{:L('SAVE_ORDER')}</button>&nbsp;
					<a href="http://5kcrm.com/index.php?m=doc&a=index&id=55" target="_blank" style="font-size: 12px;color: rgb(255, 102, 0);"><img width="20px;" src="__PUBLIC__/img/help.png"/> {:L('HELP')}</a>
					
                    <div class="pull-right">
                        <button class="btn btn-primary" type="button" id="add"><i class="icon-plus"></i>&nbsp; {:L('ADD_FIELDS')}</button>
                    </div>
                </div></p>
            </div>
			<div class="span10">
				<table class="table table-hover table-striped table_thead_fixed" width="95%" border="0" cellspacing="1" cellpadding="0">
					<notempty name="fields">
					<thead>
						<tr>
							<th width="10%"><input type="checkbox" name="check_all" id="check_all" class="check_all"/> &nbsp;</th>
							<th width="20%">{:L('LABEL_NAME')}</th>
							<th width="20%">{:L('FIELDS_NAME')}</th>
							<th width="20%">{:L('FIELDS_TYPE')}</th>
							<th width="30%">{:L('OPERATING')}</th>
						</tr>
					</thead>
					<tfoot>
						<tr>
							<td colspan="5">
								<div class="span8"><span style="color: rgb(243, 40, 12);">{:L('HINT_FIELDS')}</span></div>
							</td>
						</tr>
					</tfoot>
					<tbody>
						<volist name="fields" id="vo">
							<tr>
								<td><input type="checkbox" class="list" name="field_id[]" value="{$vo.field_id}"/>
								</td>
								<td>{$vo.name}</td>
								<td>{$vo.field}</td>
								<td>
									<if condition="$vo['form_type'] == 'box'">{:L('SELECTED')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'editor'" />{:L('THE_EDITOR')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'text'" />{:L('SINGLE_LINE_TEXT')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'textarea'" />{:L('MULTILINE_TEXT')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'datetime'" />{:L('DATE')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'number'" />{:L('NUMBER')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'floatnumber'" />{:L('NUMBER')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'user'" />{:L('USERS')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'address'" />{:L('ADDRESS')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'phone'" />{:L('TELEPHONE')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'mobile'" />{:L('PHONE')}({$vo.form_type})
									<elseif condition="$vo['form_type'] == 'email'" />{:L('EMAIL')}({$vo.form_type})
									<else /><span style="color:red;">{:L('SPECIAL_FIELD_ACCESS_IS_LIMITED')}</span>
									</if>
								</td>
								<td>
									<if condition="$vo['operating'] == 0 or $vo['operating'] == 1 "><a class="edit" href="javascript:void(0)" rel="{$vo.field_id}">{:L('EDIT')}</a><else /><s style="color:rgb(187, 180, 180);">{:L('EDIT')}</s></if> &nbsp;
									<if condition="$vo['operating'] == 0 or $vo['operating'] == 3 "><a class="delete" href="javascript:void(0)" rel="{$vo.field_id}">{:L('DELETE')}</a><else /><s style="color:rgb(187, 180, 180);">{:L('DELETE')}</s></if> &nbsp;
									<if condition="$vo['form_type'] != 'user' and $vo['in_index'] == 0"><a class="indexShow" href="javascript:void(0)" rel="{$vo.field_id}">{:L('THE_LIST_SHOWS')}</a><elseif condition="$vo['form_type'] != 'user' and $vo['in_index'] == 1"/><a class="indexShow" href="javascript:void(0)" rel="{$vo.field_id}">{:L('CANCEL_THE_LIST')}</a></if>&nbsp;
									<if condition="$vo['form_type'] == 'b_box'"><a href="{:U('setting/businessstatus','model='.$_GET['model'])}">{:L('SPECIAL_SETTING')}</a><elseif condition="$vo['form_type'] == 'p_box'"/><a href="{:U('product/category','model='.$_GET['model'])}">{:L('SPECIAL_SETTING')}</a></if>
								</td>
							</tr>
						</volist>
					</tbody>
					<else />
						<tr>
							<td>{:L('EMPTY_TPL_DATA')}</td>
						</tr>
					</notempty>
				</table>
			</div> 
		</form>
	</div>
<div class="hide" id="dialog_field_add" title="{:L('ADD_FIELDS')}">loading...</div>
<div class="hide" id="dialog_field_edit" title="{:L('EDIT_FIELDS')}">loading...</div>
</div>
<script type="text/javascript">	
$("#dialog_field_add").dialog({
	autoOpen: false,
	modal: true,
	width: 600,
	maxHeight: 600,
	position: ["center",100]
});
$("#dialog_field_edit").dialog({
	autoOpen: false,
	modal: true,
	width: 600,
	maxHeight: 600,
	position: ["center",100]
});

$("table tbody").sortable({connectWith: "table tbody"});
function checkForm(){
	if(confirm('{:L('DELETE_THE_SELECTED_FIELDS_OPERATION_CANNOT_BE_RESTORED')}')){
		return true;
	}else{
		return false;
	}
}
$(function(){
	
	$("#check_all").click(function(){
		$("input[class='list']").prop('checked', $(this).prop("checked"));
	});
	$("#add").click(function(){
		$("#dialog_field_add").dialog('open');
		$("#dialog_field_add").load('{:U("setting/fieldadd","model=$model")}');
	});
	$(".edit").click(function(){
		var id = $(this).attr('rel');
		$("#dialog_field_edit").dialog('open');
		$("#dialog_field_edit").load('{:U("setting/fieldedit","field_id")}'+id);
	});
	$(".delete").click(function(){
		var id = $(this).attr('rel');
        if(confirm('{:L('DELETE_THE_SELECTED_FIELDS_OPERATION_CANNOT_BE_RESTORED')}')){
            window.location.assign('{:U("setting/fielddelete","field_id")}'+id);
        }
	});
	$(".indexShow").click(function(){
		var id = $(this).attr('rel');
        window.location.assign('{:U("setting/indexShow","field_id")}'+id);
	});
	$("#sort_btn").click(
		function() {
			position = [];
			$.each($(".list"), function(i, item){position.push(item.value)});
			$.get('{:U("setting/fieldsort")}',{postion:position.join(',')}, function(data){
				if (data.status == 1) {
					$('.alert.alert-success').remove();
					$(".page-header").after('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>' + data.info + '</div>');
				} else {
					$('.alert.alert-error').remove();
					$(".page-header").after('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>' + data.info + '</div>');
				}
			}, 'json');
		}
	);
});
</script>
<include file="Public:footer" />